/*
 * $Id: LogEvent.java 17 2014-08-28 10:52:50Z ratking $
 *
 * Copyleft (C) 2014 RatKing. All wrongs reserved.
 */
package cn.ratking.demo.jaws7.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;

/**
 * 日志信息
 *
 * @author ljg
 */
@Entity
@Table(name = "T_LogEvent")
public class LogEvent implements Serializable {
     private static final long serialVersionUID = 1L;

    /** 日志类型：1-系统日志 */
    public static final int LOGTYPE_SYSTEM = 1;
    /** 日志类型：2-安全日志 */
    public static final int LOGTYPE_SECURITY = 2;
    /** 日志类型：3-应用日志 */
    public static final int LOGTYPE_APPLICATION = 3;
    /** 日志级别：1-信息 */
    public static final int LOGLEVEL_INFO = 1;
    /** 日志级别：2-警告 */
    public static final int LOGLEVEL_WARN = 2;
    /** 日志级别：3-错误 */
    public static final int LOGLEVEL_ERROR = 3;
    /** 描述信息description的最大字节 */
    public static final int LOGLEVEL_DESC_BYTES = 2000;
    /** 日志ID */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long logEventId;
    /** 日志类型(1-系统日志 2-安全日志 3-应用日志) */
    private int logType;
    /** 日志级别(1-信息 2-警告 3-错误) */
    private int logLevel;
    /** 操作来源(模块名称、用户所访问的页面URL或产生事件的JavaBean名称) */
    private String eventSource;
    /** 描述信息 */
    @Size(max = 2000)
    @Column(length = 2000)
    private String description;
    /** 用户ID(用户登录到系统所使用的唯一标识) */
    private String userId;
    /** 用户姓名 */
    private String userName;
    /** 部门名称(用户所在的单位或部门的名称) */
    private String deptName;
    /** 客户端IP */
    private String clientIp;
    /** 创建时间 */
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;

    /** 无参构造方法 */
    public LogEvent() {
    }

    /**
     * 带参数的构造方法
     *
     * @param description
     */
    public LogEvent(String description) {
        this.logType = LogEvent.LOGTYPE_APPLICATION;
        this.logLevel = LogEvent.LOGLEVEL_INFO;
        this.description = description;
    }

    /**
     * 带参数的构造方法
     *
     * @param logType
     * @param logLevel
     * @param description
     */
    public LogEvent(int logType, int logLevel, String description) {
        this.logType = logType;
        this.logLevel = logLevel;
        this.description = description;
    }

    public Long getLogEventId() {
        return logEventId;
    }

    public void setLogEventId(Long logEventId) {
        this.logEventId = logEventId;
    }

    public int getLogType() {
        return logType;
    }

    public void setLogType(int logType) {
        this.logType = logType;
    }

    public int getLogLevel() {
        return logLevel;
    }

    public void setLogLevel(int logLevel) {
        this.logLevel = logLevel;
    }

    public String getEventSource() {
        return eventSource;
    }

    public void setEventSource(String eventSource) {
        this.eventSource = eventSource;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getClientIp() {
        return clientIp;
    }

    public void setClientIp(String clientIp) {
        this.clientIp = clientIp;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * 返回测试字符串
     *
     * @return 测试字符串
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();

        sb.append("[LogEvent: logEventId=").append(logEventId);
        sb.append(", logType=").append(logType);
        sb.append(", logLevel=").append(logLevel);
        sb.append(", eventSource=").append(eventSource);
        sb.append(", description=").append(description);
        sb.append(", userId=").append(userId);
        sb.append(", userName=").append(userName);
        sb.append(", deptName=").append(deptName);
        sb.append(", clientIp=").append(clientIp);
        sb.append(", createTime=").append(createTime);
        sb.append("]");

        return sb.toString();
    }
}
